#pragma once
#include "afxwin.h"
#include "SOM.h"
#include "Hebbian.h"
#include "MultiscaleNet.h"
#include "BasicFunction.h"
#include "atlimage.h"
#include "ImageLab.h"
#include "MultiscaleCrossModal.h"
#include "LinguisticProcessing.h"
using namespace std;

// CCrossModalDialog dialog

class CCrossModalDialog : public CDialog
{
	DECLARE_DYNAMIC(CCrossModalDialog)

	using CDialog::Create;
public:
	CCrossModalDialog(CWnd* pParent = NULL);   // standard constructor
	virtual ~CCrossModalDialog();
	BOOL Create();

// Dialog Data
	enum { IDD = IDD_CROSSMODAL };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnOK();

private:
	int				dialogid;
	CWnd*	parent;

	MultiscaleNet*						multiscalenet;			//First SOM
	CSOM*								linguisticsom;				//Lingusitc SOM
	CHebbian*							hebbianlink;				//Hebbian links between the two SOMs
	CMultiscaleCrossModal*		crossmodal;				//Cross Modal
	CLinguisticProcessing*			linguisticprocessing;	//Linguistic Processing class


	CBasicFunction					bf;							//Some basic fucntions

	CImage								imageview;				//View of the image som
	CImage								linguisticview;			//View of the linguistic SOM

	rgb**									imagelpa;					//Pointer to the image som view data
	rgb**									linguisticlpa;				//Pointer to the linguistic som view data

	rgb**									imagelparecovery;		//Temporal data for image view
	rgb**									linguisticlparecovery;	//Temporal data for linguisti vewi

	rgb										SELECTCOLOUR;	//Colour of node when it is selected
	rgb										BLANKCOLOUR;	//Colour of node
	rgb										BACKGROUNDCOLOUR;	//Background colour of the view
	rgb										LINECOLOUR;		//Line colour connecting the nodes
	rgb										BOUNDARYCOLOUR;	//Boundary colour of the view

	vector<vector<RECT>>		imagenodeposition;	//Position of the nodes in the image view
	vector<vector<RECT>>		linguisticnodeposition;	//Position of nodes in the linguistic view

	vector<string>						imagelist;					//List of images being retreived
	vector<string>						linguisticlist;				//List of documents being retrieved
	vector<string>						newlist;						//List of images newly added
	vector<vector<string>>		keywordsfornode;		//Keywords associated to each linguistic node

	//Set recovery of the view
	void SetRecovery(void);

public:
	//Plot the image SOM
	void	PlotImageSOM(unsigned int rows, unsigned int columns);
	//Plot the linguistic SOM
	void PlotLinguisticSOM(unsigned int rows, unsigned int columns);
	//Recolour the node
	void DrawImageNode(RECT rect, rgb nodecolour);
	//Recolour the node
	void DrawLinguisticNode(RECT rect, rgb nodecolour);
	//Normalize the input
	void NormalizeData(std::vector<vector<vector<double> > > &input, unsigned int normalizescale);
	//Set the keywords for each node
	void	SetKeywordsForNode();
	void	ActiveNodes(_2dpoint imageposition, _2dpoint linguisticposition);
	void	ResetDialog();

	//Reset the views
	void ResetImageView();
	void ResetLinguisticView();

	DECLARE_MESSAGE_MAP()
	afx_msg void OnBnClickedCrossmodalTrain();
	afx_msg void OnLbnSelchangeCrossmodalImagelist();
	afx_msg void OnBnClickedCrossmodalLoad();
	afx_msg void OnLbnSelchangeCrossmodalLinguisticlist();
	afx_msg void OnBnClickedCrossmodalRetrieveimage();
	afx_msg void OnBnClickedCrossmodalAddimage();
};
